(function($){
	$.fn.ddl = function(options){
		var defaults= {
			type:"time",
			Li:["0时","1时","2时","3时","4时","5时","6时","7时","8时","9时","10时","11时","12时","13时","14时","15时","16时","17时","18时","19时","20时","21时","22时","23时"],
			callback:function(){}
		}
		var opts = $.extend({},defaults,options);

		function createLi(){
			var ul = $("<ul />").css("display","none").addClass("ddl");
			for(var i=0; i<opts.Li.length; i++){
				var li = $("<li value='" + i + "'>" + opts.Li[i] + "</li>")
				ul.append(li);
			}
			return ul;
		}
		return $(this).each(function(){
			if(opts.type=="time")
				$(this).after(createLi());
			$(this).next().addClass("ddl");

			$(this).click(function(e){
				if(!$(this).hasClass("disabled")){
					e.stopPropagation();
					$(".ddl").hide();
					
					opts.callback();

					var ul= $(this).next();
					if(ul.css("display")=="none")
						$(this).next().slideDown("fast");
					else ul.slideUp("fast");
					var thisElement = $(this);
	
					$("li", ul).click(function(e){
						e.stopPropagation();
						ul.find("li").removeClass("choose");
						$(this).addClass("choose");
						$(this).parent().hide();
						var newchoice=$.subStr($(this).html(),3);
						if(opts.type == "time") newchoice = $(this).attr("value");
						thisElement.find("span").html(newchoice).attr("value",$(this).attr("value"));
						$(".screen-r input").addClass("hover");
					});
	
					$("body:not(li)").one('click',function() {
						e.stopPropagation();
						ul.hide();
					});		
				}		
			});


		});
	}
})(jQuery);